<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: aqua;
            border-radius: 50%;
            position: absolute;
            left: 0px;
            top: 0px;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script>
        var boxEle = document.querySelector(".box");
        boxEle.onmousedown = function(event) {
            var e = event || window.event;
            var x = e.clientX;
            var y = e.clientY;
            var offsetLeftNum = boxEle.offsetLeft;
            var offsetTopNum = boxEle.offsetTop;
            boxEle.onmousemove = function(event) {
                var e = event || window.event;
                var xx = e.clientX;
                var yy = e.clientY;
                var disx = xx - x + offsetLeftNum;
                var disy = yy - y + offsetTopNum;
                boxEle.style.left = disx + "px";
                boxEle.style.top = disy + "px";
            };
            boxEle.onmouseup = function() {
                boxEle.onmousemove = "";
            };
        };
    </script>
</body>

</html>